package org.zkoss.zktc.testsample;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.zkoss.zktc.core.junit.TestCaseBase;
import org.zkoss.zktc.core.widget.Widget;

/**
 * 
 * @author dennis
 *
 */
public class ForumTestCase extends TestCaseBase{

	
	public String getUrl(){
		//get forum url from config file, zktc-testcase.properties 
		return getConfigProperty("forumUrl");
	}
	
	@Test
	public void testForumLogin(){
		navigate(getUrl());
		
		Widget login = findWidget("#reglang-box @toolbarbutton");
		Assert.assertNotNull(login);
		Assert.assertEquals("Login",login.getLabel());
		login.click();
		
		//wait for redirect ready
		waitForReady();
		
		Widget username = findWidget("$username");
		Assert.assertNotNull(username);
		Widget password = findWidget("$password");
		Assert.assertNotNull(password);
		Widget confirmBtn = findWidget("$confirmBtn");
		Assert.assertNotNull(confirmBtn);
		
		username.replace("yyyyy");//your real forum account
		password.replace("xxxxx");//your real password
		confirmBtn.click();
		
		//wait for redirect ready
		waitForReady();
		
		List<Widget> btns = findWidgets("#reglang-box @toolbarbutton");
		
		Assert.assertEquals("dennis",btns.get(0).getLabel());
		Assert.assertEquals("Logout",btns.get(1).getLabel());
		btns.get(1).click();
		
		
		//wait for redirect ready
		waitForReady();
		
		login = findWidget("#reglang-box @toolbarbutton");
		Assert.assertNotNull(login);
		Assert.assertEquals("Login",login.getLabel());
		
	}
	
	@Test
	public void testMainPage(){
		navigate(getUrl());
		Widget grid = findWidget("$categoryListGrid");
		List<Widget> rows = grid.findWidgets("@row"); 
		Assert.assertEquals("Help",rows.get(0).findWidget("@a").getLabel());
		Assert.assertEquals("ZK Studio",rows.get(1).findWidget("@a").getLabel());
		Assert.assertEquals("General",rows.get(2).findWidget("@a").getLabel());
		Assert.assertEquals("Announcements",rows.get(3).findWidget("@a").getLabel());
		Assert.assertEquals("Installation",rows.get(4).findWidget("@a").getLabel());
		
	}
	
}
